/*
 ============================================================================
 Name		: P2PManager.h
 Author	  : 
 Version	 : 1.0
 Copyright   : 
 Description : CP2PManager declaration
 ============================================================================
 */

#ifndef P2PMANAGER_H
#define P2PMANAGER_H

// INCLUDES
#include <e32std.h>
#include <e32base.h>

#include "P2PMessageSupplier.h"

class CNfcConnector;
class CP2PMessage;

// CLASS DECLARATION

/**
 *  CP2PManager
 * 
 */
class CP2PManager : public CBase, private MP2PMessageSupplier
	{
public:
	// Constructors and destructor

	/**
	 * Destructor.
	 */
	~CP2PManager();

	/**
	 * Two-phased constructor.
	 */
	static CP2PManager* NewL();

	/**
	 * Two-phased constructor.
	 */
	static CP2PManager* NewLC();
	
	void SendMessageL(const TDesC8& aAppId, const TDesC8& aMessageId, const TDesC8& aContent, TTime aValidUntil);

	void SetResponseL(const TDesC8& aAppId, const TDesC8& aMessageId, const TDesC8& aContent, TTime aValidUntil);
	
	HBufC8* TransactionLogL(const TDesC8& aAppId) const;

private:

	// MP2PMessageSupplier implementation begins
	void ConnectionEstablished();
	void ConnectionLost();
	HBufC8* GetNextMessagePayload();
	void MessageReceived(const TDesC8& aIncomingPayload);
	void SendResult(TInt aError);
	// MP2PMessageSupplier implementation ends

	/**
	 * Constructor for performing 1st stage construction
	 */
	CP2PManager();

	/**
	 * EPOC default constructor for performing 2nd stage construction
	 */
	void ConstructL();

    CNfcConnector* iConnector;
	
	RPointerArray<CP2PMessage> iSendQueue;
	RPointerArray<CP2PMessage> iResponseMap;
	CP2PMessage* iCurrentlySending;
	RPointerArray<CP2PMessage> iTransactionLog;
	
	};

#endif // P2PMANAGER_H
